package com.earthquake.monitor_system.config;

import com.earthquake.monitor_system.controller.interceptor.ProjectInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private ProjectInterceptor projectInterceptor;
    @Value("${file.uploadPath}")
    private String uploadPath;
    @Value("${file.fileRoot}")
    private String fileRoot;
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(fileRoot).addResourceLocations("file:"+uploadPath);
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       registry.addInterceptor(projectInterceptor)
               .addPathPatterns("/**")
               .excludePathPatterns("/user/login","/user/register","/user/code","/upload/**","/files/**");
    }
}
